package com.sml.exception;

import com.sml.pojo.Result;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice //  全局异常处理
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class) //  处理所有异常
    public Result<String> exceptionHandler(Exception e) {
        e.printStackTrace();
        //统一返回结果
        return Result.error(StringUtils.hasLength(e.getMessage()) ? e.getMessage() : "操作异常");
    }
}
